package com.cy.store.controller;

import com.cy.store.entity.Product;
import com.cy.store.service.IProductService;
import com.cy.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/products")
public class ProductController extends BaseController {

    @Autowired
    private IProductService productService;

    /**
     * 进入页面后显示热销的四款产品
     *
     * @return
     */
    @RequestMapping("/hot_list")
    public JsonResult<List<Product>> getHotList() {
        List<Product> list = productService.findHostList();
        return new JsonResult<>(OK, list);
    }

    /**
     * 进入页面后显示最新的四款产品
     *
     * @return
     */
    @RequestMapping("/new_list")
    public JsonResult<List<Product>> getNewList() {
        List<Product> list = productService.findNewList();
        return new JsonResult<>(OK, list);
    }

    @GetMapping("/details/{id}")
    public JsonResult<Product> getById(@PathVariable("id") Integer id) {
        Product product = productService.findById(id);
        return new JsonResult<>(OK, product);
    }
}
